import AppInfoItem from '@/components/appInfoItem/index'
import { Options } from '@/utils/constant'
// import { setLocalStorage, getLocalStorage } from '@/utils/localStorage'
import { isNull } from '@/utils/utils'
import bus from '@/api/bus'
// import { getItemList } from '@/api/api'
import { mapGetters } from 'vuex'
import virtualTableJs from '@/mixin/virtualTable'
export default {
  mixins: [virtualTableJs],
  components: {
    AppInfoItem
  },
  props: {
    // mipVisible: {
    //   type: Boolean,
    //   default: true
    // }
    // rowCurr: {
    //   type: Object,
    //   default: {}
    // }
  },
  data() {
    return {
      isSetEmergencyValue: this.$store.state.user.appSetting.isSetEmergencyValue,
      isShowLevelEdit: true,
      applyInfoHospital: window.g.applyInfoHospital,
      isSetRemarkInfo: window.g.IS_SET_REMARKINFO,
      hospitalCode: this.$store.state.user.hospitalCode,
      // 患者来源
      patientTypeItemOptions: Options.patientTypeItemOptions,
      // 急诊标志
      emergencyTypes: Options.emergencyOptions,
      emergencyOptionsOnly: window.g.emergencyOptionsOnly,
      emergencyOptionsRevertMap: Options.emergencyOptionsRevertMap,
      emergencyOptionsMap: Options.emergencyOptionsMap,
      isHcv: false,
      isRpr: false,
      isHiv: false,
      isHbsag: false,
      isPRG: false,
      isSCR: false
    }
  },
  computed: {
    ...mapGetters(['rowCurr', 'gradeList', 'privacyLevelList']),
    appConfig() {
      let appConfig = this.$store.state.settings.appConfig
      return appConfig
    },
    isShowChiefComplaint() {
      return (this.$store.state.user.appSetting && this.$store.state.user.appSetting.isUseChiefComplaint) || false
    },
    isShowEmergencyTag() {
      return this.appConfig && this.appConfig.baseConfig && this.appConfig.baseConfig.isShowEmergencyTag
    }
  },
  watch: {},
  created() {
    if (process.env.NODE_ENV != 'production') {
      this.isSetEmergencyValue = true
      console.warn('this.isSetEmergencyValue', this.isSetEmergencyValue)
    }
  },
  mounted() {
    this.patientTypeItemOptions = this.patSourceOptionsFun()
    this.emergencyTypes = this.emergencyTypesFun()
    this.emergencyOptionsRevertMap = this.emergencyOptionsRevertMapFun()
    this.emergencyOptionsMap = this.emergencyOptionsMapFun()
    // console.log('applyinfo.js=>this.emergencyOptionsMap=>', this.emergencyOptionsMap)
    const tokenInfoString = localStorage.getItem('JJYY_SET_TOKENINFO')
    if (tokenInfoString && tokenInfoString.indexOf('applyDepartment') > -1) {
      const tokenInfo = JSON.parse(tokenInfoString)
      if (tokenInfo.applyDepartment) {
        this.isShowLevelEdit = false
      }
    }
    if(this.isShowEmergencyTag) {
      this.emergencyOptionsRevertMap['四级急诊'] = this.emergencyOptionsRevertMap['急诊'];
      delete this.emergencyOptionsRevertMap['急诊'];
      this.emergencyOptionsMap[1] = '四级急诊'
      this.emergencyTypes[1].label = '四级急诊'
    }
  },
  methods: {
    async getPrivacyLevel() {
      // const res = await getItemList({ HospitalCode: this.$store.state.user.hospitalCode, type: '保密级别' })
      // let list = res.content.list || []
      // // const h = this.$createElement
      // list.forEach((it) => {
      //   it.value = it.item
      //   it.label = it.item
      //   return it
      // })
      // this.privacyLevelList = list
      if (this.privacyLevelList.length === 0) {
        // console.log('applyInfo.js=>获取保密级别')
        let params = { HospitalCode: this.$store.state.user.hospitalCode, type: '保密级别' }
        await this.$store.dispatch('settings/set_privacyLevelList', params)
        // console.log('this.privacyLevelList', this.privacyLevelList)
      }
    },
    // getIsConfigBedsideAlong() {
    //   const _t = this.appConfig && this.appConfig.checkHisTableColumnsConfig ? this.appConfig.checkHisTableColumnsConfig : this.columnsConfig
    //   _t.forEach(item => {
    //     if (item.prop == 'bedside' && item.show) {
    //       return true
    //     }
    //   })
    //   return false
    // },
    // 通过name来匹配value
    getEmergencyValueByName(name) {
      let value = ''
      let emergencyOptions = this.appConfig.checkHisTable || Options.emergencyOptions
      emergencyOptions.forEach(item => {
        if (item.label == name) {
          value = item.value
          return
        }
      })
      return value
    },
    patSourceOptionsFun() {
      let patientSourceOptions = (this.appConfig.checkPatTypeTable || Options.patientTypeItemOptions)
      let psArr = []
      patientSourceOptions.forEach(item => {
        item.name = item.label || item.name
        delete item.label
        psArr.push(item)
      })
      return psArr
    },
    emergencyTypesFun() {
      return this.appConfig.checkHisTable && this.appConfig.checkHisTable.length && this.appConfig.checkHisTable || Options.emergencyOptions
    },
    emergencyOptionsMapFun() {
      let map = {
        '': ''
      }
      let emergencyTable = this.appConfig.checkHisTable || Options.emergencyOptions
      // this.appConfig.checkHisTable || Options.emergencyOptions
      emergencyTable.forEach(item => {
        let value = ''
        if (isNull(item.value) && (item.name || item.label)) {
          // console.log('isNull', item.value)
          value = this.getEmergencyValueByName(item.name || item.label)
          // console.log('value', value)
        } else {
          // console.log('noit isNull', item.value)
          value = item.value
        }
        map[value] = item.name || item.label
      })
      // console.log('map', map)
      return map
    },
    emergencyOptionsRevertMapFun() {
      let map = {
        '': ''
      }
      let emergencyTable = this.appConfig.checkHisTable || Options.emergencyOptions
      emergencyTable.forEach(item => {
        map[item.name || item.label] = item.value
      })
      return map
    },
    feeStatusText(val) {
      if (val === true) {
        return '已收费'
      } else if (val === false) {
        return '未收费'
      } else {
        return ''
      }
    },
    changeEmergency(data) {
      let row = this.rowCurr
      // console.log('changeEmergency——value', value)
      let labelName = this.renderEmergencyLabel(value)
      row.grade = labelName
      row.emergency = value
      row.emergencylabel = labelName
      row.emergencyInfo = labelName
      this.$emit('refreshValue', {
        field: 'patEmergency',
        value: data
      })
      // 更新this.mix_tableData列表中的保密等级字段
      bus.$emit('changeListData',{
        row: this.rowCurr,
        type: 'patEmergency',
        value: data
      })
      bus.$emit('checkPostMsg', {
        type: 'patEmergency',
        data: { emergency: data.toString() }
      })
      // console.log('row', row)
      this.$store.dispatch('patient/setRowCurr', row)
    },
    changePrivacyLevel(data) { // 保密等级
      console.log('changePrivacyLevel=>data', data)
      let row = this.rowCurr
      row.privacyLevel = data
      this.$emit('refreshValue', {
        field: 'patPrivacyLevel',
        value: data
      })
      // 更新this.mix_tableData列表中的保密等级字段
      bus.$emit('changeListData',{
        row: this.rowCurr,
        type: 'patPrivacyLevel',
        value: data
      })
      bus.$emit('checkPostMsg', {
        type: 'patPrivacyLevel',
        data: { privacyLevel: data }
      })
      this.$store.dispatch('patient/setRowCurr', row)
    },
    changeInfoFunc(param, data) {
      let row = this.rowCurr
      this.$store.dispatch('patient/setRowCurr', row)
      this.$emit('refreshValue', {
        field: param,
        value: data
      })
      // 更新this.mix_tableData列表中的保密等级字段
      bus.$emit('changeListData',{
        row: this.rowCurr,
        type: param,
        value: data
      })
      bus.$emit('checkPostMsg', {
        type: param,
        data: { param: data }
      })
    },
    changeHBsAg(data) { // 乙肝病毒
      let row = this.rowCurr
      row.hbsag = data
      this.isHbsag = data === '阳性'
      this.changeInfoFunc('hbsag', data)
    },
    changeHIV(data) { // 乙肝病毒
      let row = this.rowCurr
      row.hiv = data
      this.isHiv = data === '阳性'
      this.changeInfoFunc('hiv', data)
    },
    changeRPR(data) { // 乙肝病毒
      let row = this.rowCurr
      row.rpr = data
      this.isRpr = data === '阳性'
      this.changeInfoFunc('rpr', data)
    },
    changeHCV(data) { // 乙肝病毒
      let row = this.rowCurr
      row.hcv = data
      this.isHcv = data === '阳性'
      this.changeInfoFunc('hcv', data)
    },
    changePRG(data) { // 乙肝病毒
      let row = this.rowCurr
      row.lisSerumGastric = data
      this.isPRG = data === '阳性'
      this.changeInfoFunc('lisSerumGastric', data)
    },
    changeSCR(data) { // 乙肝病毒
      let row = this.rowCurr
      row.creatinine = data
      this.isSCR = data === '阳性'
      this.changeInfoFunc('creatinine', data)
    },
    async handleVIPChange(data) {
      let row = this.rowCurr
      // console.log('handleEmergencyChange_data', data)
      let value = ''
      // let intValue = ''
      if (data) {
        value = 'VIP'
        row.grade = value
        // intValue = this.renderEmergencyInt(value)
        // row.emergency = row.emergencyStorage
        // row.emergencylabel = this.renderEmergencyName(row.emergency)
        row.isVIP = data
        row.isJZ = false
        // const isConfigBedsideAlong = this.getIsConfigBedsideAlong()
        // if (isConfigBedsideAlong) {
        //   row.extras.forEach(element => {
        //     element.key === 'Bedside' ? '非床旁' : null
        //   })
        // }
      } else {
        if (this.gradeList.length === 0) {
          let params = { HospitalCode: this.hospitalCode, Dep: this.$store.state.depArea || '', type: '优先级' }
          await this.$store.dispatch('settings/set_gradeList', params)
        }
        let findResult = -1
        findResult = this.gradeList.findIndex(item => item.item == '普通')
        if (findResult > -1) {
          value = '普通'
          row.grade = '普通'
          // row.emergency = this.renderEmergencyInt('普通')
          // row.emergencylabel = '普通'
        } else {
          findResult = this.gradeList.findIndex(item => item.item == '中')
          if (findResult > -1) {
            value = '中'
            row.grade = '中'
            // row.emergency = 0
            // row.emergencylabel = '普通'
          } else {
            value = ''
            row.grade = ''
            // row.emergency = this.renderEmergencyInt('')
            // row.emergencylabel = ''
          }
        }
      }
      this.$store.dispatch('patient/setRowCurr', row)
      this.$emit('refreshValue', {
        field: 'patPriorityLevel',
        value: value
      })
      bus.$emit('changeListData',{
        row: this.rowCurr,
        type: 'patPriorityLevel',
        value: value
      })
      bus.$emit('checkPostMsg', {
        type: 'patPriorityLevel',
        data: { grade: value }
      })
    },
    async handleJZChange(data) {
      let row = this.rowCurr
      let value = ''
      // let intValue = ''
      if (data) {
        // this.$store.state.user.appSetting.isSetEmergencyValue ? value = '四级急诊' : value = '急诊'
        value = '急诊'
        row.grade = '急诊'
        // intValue = this.renderEmergencyInt(value)
        // row.emergency = intValue.toString()
        // row.emergencylabel = value
        // row.emergencyInfo = value
        row.isVIP = false
      } else {
        let params = { HospitalCode: this.hospitalCode, Dep: this.$store.state.depArea || '', type: '优先级' }
        await this.$store.dispatch('settings/set_gradeList', params)
        let findResult = -1
        findResult = this.gradeList.findIndex(item => item.item == '普通')
        if (findResult > -1) {
          value = '普通'
          row.grade = '普通'
          // row.emergencylabel = this.renderEmergencyName('0')
          // row.emergency = this.renderEmergencyInt(row.emergencylabel)
        } else {
          findResult = this.gradeList.findIndex(item => item.item == '中')
          if (findResult > -1) {
            value = '中'
            row.grade = '中'
            // row.emergencylabel = this.renderEmergencyName('0')
            // row.emergency = this.renderEmergencyInt(row.emergencylabel)
          } else {
            value = ''
            row.grade = ''
            // row.emergency = this.renderEmergencyInt('')
            // row.emergencylabel = ''
          }
        }
      }
      row.isJZ = data
      this.$emit('refreshValue', {
        field: 'patPriorityLevel',
        value: value
      })
      bus.$emit('changeListData',{
        row: this.rowCurr,
        type: 'patPriorityLevel',
        value: value
      })
      bus.$emit('checkPostMsg', {
        type: 'patPriorityLevel',
        data: { grade: value }
      })
      this.$store.dispatch('patient/setRowCurr', row)
      // 更新this.mix_tableData列表中的保密等级字段
      // bus.$emit('changeListData',{
      //   row: this.rowCurr,
      //   type: 'patEmergency',
      //   value: row.emergency,
      //   intValue: intValue,
      //   grade: row.grade
      // })
      // console.error('row.emergency', row.emergency)
      // bus.$emit('checkPostMsg', {
      //   type: 'patEmergency',
      //   data: { emergency: row.emergency, grade: row.grade }
      // })
    },
    async handleModalityChange(data) {
      let row = this.rowCurr
      let value = ''
      // let intValue = ''
      if (data) {
        value = data
        row.examClass = data
        this.$emit('refreshValue', {
          field: 'patModalityType',
          value: value
        })
        bus.$emit('changeListData',{
          row: this.rowCurr,
          type: 'patModalityType',
          value: value
        })
        bus.$emit('checkPostMsg', {
          type: 'patModalityType',
          data: { modalityType: value }
        })
        this.$store.dispatch('patient/setRowCurr', row)
      }
    },
    handleBedSideChange(data) {
      let row = this.rowCurr
      row.extras.forEach(element => {
        element.key === 'Bedside' ? ( data ? element.value = '床旁' : element.value = '非床旁') : null
      })
      let values = {
        isOverBed : data,
        extras : row.extras
      }
      this.$store.dispatch('patient/setRowCurr', row)
      bus.$emit('changeListData',{
        row: row,
        type: 'isOverBed',
        value: values
      })
      bus.$emit('checkPostMsg', {
        type: 'isOverBed',
        data:  data ?  '床旁':'非床旁'
      })
    },
    // 修改手机号码
    editPhone(phone) {
      if (!this.rowCurr.patientId) {
        this.$message({
          type: 'info',
          message: '请先选择一个患者信息'
        })
        return false
      }
      this.$prompt('您确定要修改当前患者的手机号码', '温馨提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValue: phone,
        inputPattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
        inputValidator: (val) => {
          if (val === null) {
            return true
          }
          return !(val.length > 11 || val.length < 11)
        },
        inputErrorMessage: '格式不正确'
      }).then((e) => {
        // console.log('eeee', e)
        if (e.action == 'confirm') {
          let row = this.rowCurr
          row.patientPhone = e.value
          this.$store.dispatch('patient/setRowCurr', row)
          // for (let i = 0; i < this.mix_tableData.length; i++) {
          //   if (this.mix_tableData[i].patientId === this.rowCurr.patientId) {
          //     this.mix_tableData[i].patientPhone = this.rowCurr.patientPhone
          //     this.mix_tableData[i].patient.patientPhone = this.rowCurr.patientPhone
          //   }
          // }
          this.$emit('refreshValue', {
            field: 'patientPhone',
            value: e.value
          })
          let value = e.value
          bus.$emit('changeListData',{
            row: this.rowCurr,
            type: 'patientPhone',
            value: value
          })
          // bus.$emit('checkPostMsg', {
          //   type: 'patPhoneEdit',
          //   data: { newPhone: e.value }
          // })
          bus.$emit('checkPostMsg', {
            type: 'patPatTelephone',
            data: { patTelephone: e.value }
          })
        } else {
          this.$message({
            type: 'info',
            message: '操作被取消'
          })
        }
      }).catch((e) => {
        console.log('catch_e', e)
        if (e == 'cancel') {
          this.$message({
            type: 'info',
            message: '操作被取消'
          })
        } else {
          this.$message({
            type: 'info',
            message: '出错了' + e
          })
        }
      })
    },
    // 修改优先级
    async editLevel(value) {
      let that = this
      if (!this.rowCurr.patientId) {
        this.$message({
          type: 'info',
          message: '请先选择一个患者信息'
        })
        return false
      }
      console.log('获取优先级')
      let params = { HospitalCode: this.hospitalCode, Dep: this.$store.state.depArea || '', type: '优先级' }
      await this.$store.dispatch('settings/set_gradeList', params)
      let list = this.gradeList
      // const res = await getItemList({ HospitalCode: this.hospitalCode, Dep: this.$store.state.depArea || '', type: '优先级' })
      // console.log('==###==getItemList——res==###==', res)
      // let list = res.content.list || []
      // console.log('优先级list', list)
      // let findResult = list.findIndex(item => item.item == '普通')
      // console.log('findResult', findResult)
      // if (findResult === -1) {
      //   list.push({
      //     item: '普通'
      //   })
      // }
      const h = this.$createElement
      let attrList = []
      list.forEach((it) => {
        attrList.push(h('el-option', {
          attrs: {
            value: it.item,
            label: it.item
          }
        }))
      })
      console.log('list', list)
      console.log('attrList', attrList)
      this.$msgbox({
        title: '温馨提示',
        message: h('div', null, [
          h('p', { class: 'el-message-box__message' }, '您确定要修改当前患者的优先级 '),
          h('div', { class: 'el-message-box__input', id: 'newMessage' }, [
            h('el-select', {
              ref: 'levelFlag',
              id: 'myInitSelect',
              size: 'mini',
              data: list,
              attrs: {
                value: value,
                placeholder: '请选择优先级'
              },
              on: {
                change: (event) => {
                  console.log('event', event)
                  that.$nextTick(() => {
                    try {
                      that.$refs['levelFlag'].value = event
                    } catch (e) {
                      document.querySelector('.el-message-box .el-input input').value = event
                    }
                  }, 200)
                }
              }
            }, attrList)
          ])
        ]),
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = '保存中...'
            let value = ''
            try {
              value = this.$refs['levelFlag'].value
            } catch (e) {
              value = document.querySelector('.el-message-box .el-input input').value
            }
            // let intValue = this.renderEmergencyInt(value)
            // console.log('intValue==', intValue)
            let row = this.rowCurr
            row.grade = value
            // isJZ
            // row.emergency = row.emergencyStorage
            // row.emergencylabel = this.renderEmergencyName(row.emergency)
            console.log('row.emergencylabel==', row.emergencylabel)
            if (value == 'VIP') {
              row.isVIP = true
              row.grade = value
            } else {
              row.isVIP = false
            }
            if (row.grade === '急诊') {
              row.isJZ = true
              row.grade = value
            } else {
              row.isJZ = false
            }
            this.$store.commit('patient/SETROWCURR', row)
            console.log('SETROWCURR=>rowCurr', this.rowCurr)
            this.$emit('refreshValue', {
              field: 'patPriorityLevel',
              value: value
            })
            bus.$emit('changeListData',{
              row: this.rowCurr,
              type: 'patPriorityLevel',
              value: value
            })
            // this.changeListData(this.rowCurr, value, intValue)
            // console.log('this.mix_tableData=>', this.mix_tableData)
            // for (let i = 0; i < this.mix_tableData.length; i++) {
            //   console.log('this.mix_tableData[i].patientId', this.mix_tableData[i].patientId)
            //   console.log('this.rowCurr.patientId', this.rowCurr.patientId)
            //   if (this.mix_tableData[i].patientId === this.rowCurr.patientId) {
            //     this.mix_tableData[i].grade = value
            //     if (value == '急诊') {
            //       this.mix_tableData[i].isJZ = true
            //     } else {
            //       this.mix_tableData[i].isJZ = false
            //     }
            //     // this.mix_tableData[i].emergencylabel = value
            //     // this.mix_tableData[i].emergency = intValue
            //   }
            // }
            console.log('this.mix_tableData=>', this.mix_tableData)
            bus.$emit('checkPostMsg', {
              type: 'patPriorityLevel',
              data: { grade: value }
            })
            done()
            instance.confirmButtonLoading = false
          } else {
            done()
          }
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    },
    // 修改急诊标志
    async editEmergency(value) {
      if (!this.rowCurr.patientId) {
        this.$message({
          type: 'info',
          message: '请先选择一个患者信息'
        })
        return false
      }
      console.log('')
      let list = this.appConfig ? this.appConfig.checkHisTable : this.emergencyTypes
      const h = this.$createElement
      let attrList = []
      list.forEach((it) => {
        attrList.push(h('el-option', {
          attrs: {
            value: it.name,
            label: it.name
          }
        }))
      })
      // console.error('内容', value)
      // console.log('attrList', attrList)
      this.$msgbox({
        title: '温馨提示',
        message: h('div', null, [
          h('p', { class: 'el-message-box__message' }, '您确定要修改当前患者的急诊标志'),
          h('div', { class: 'el-message-box__input', id: 'myEmergencyMessage' }, [
            h('el-select', {
              ref: 'levelFlags',
              id: 'myEmergencySelect',
              size: 'mini',
              data: list,
              attrs: {
                value: value,
                placeholder: '请选择急诊标志'
              },
              on: {
                change: (event) => {
                  this.$nextTick(() => {
                    try {
                      this.$refs['levelFlags'].value = event
                    } catch (e) {
                      document.querySelector('.el-message-box .el-input input').value = event
                    }
                  })
                }
              }
            }, attrList)
          ])
        ]),
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = '保存中...'
            let value = ''
            try {
              value = this.$refs['levelFlags'].value
            } catch (e) {
              value = document.querySelector('.el-message-box .el-input input').value
            }
            let intValue = parseInt(this.renderEmergencyInt(value))
            console.warn('intValue', intValue)
            let row = this.rowCurr
            if (this.isSetEmergencyValue && [1, 2, 3, 4].includes(intValue)) {
              row.grade = '急诊'
            } else if (!this.isSetEmergencyValue && [1, 14, 15, 16].includes(intValue)) {
              row.grade = '急诊'
            } else {
              // row.grade = '普通'
              // console.error('this.gradeList.', this.gradeList)
              let findResult = this.gradeList.findIndex(item => item.item == '普通')
              if (findResult > -1) {
                row.grade = '普通'
              } else {
                findResult = this.gradeList.findIndex(item => item.item == '中')
                if (findResult > -1) {
                  row.grade = '中'
                } else {
                  row.grade = ''
                }
              }
            }
            row.emergency = intValue
            row.emergencylabel = value
            row.emergencyInfo = value
            if (value == 'VIP') {
              row.isVIP = true
            } else {
              row.isVIP = false
            }
            // 温附二环境数值[1, 2, 3, 4]为急诊
            if (this.isSetEmergencyValue && [1, 2, 3, 4].indexOf(intValue) > -1) {
              row.isJZ = true
            } else if (!this.isSetEmergencyValue && [1, 14, 15, 16].indexOf(intValue) > -1){
              row.isJZ = true
            } else {
              row.isJZ = false
            }
            this.$store.dispatch('patient/setRowCurr', row)
            this.$emit('refreshValue', {
              field: 'patEmergency',
              value: value
            })
            bus.$emit('changeListData', {
              row: this.rowCurr,
              type: 'patEmergency',
              value: value,
              intValue: intValue,
              grade: row.grade
            })
            bus.$emit('checkPostMsg', {
              type: 'patEmergency',
              data: { emergency: intValue.toString(), grade: row.grade }
            })
            this.$emit('refreshValue', {
              field: 'patPriorityLevel',
              value: row.grade
            })
            // bus.$emit('checkPostMsg', {
            //   type: 'patPriorityLevel',
            //   data: { grade: row.grade }
            // })
            done()
            instance.confirmButtonLoading = false
          } else {
            done()
          }
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    },
    // 修改保密级别
    async editPrivacyLevel(value) {
      if (!this.rowCurr.patientId) {
        this.$message({
          type: 'info',
          message: '请先选择一个患者信息'
        })
        return false
      }
      let params = { HospitalCode: this.$store.state.user.hospitalCode, type: '保密级别' }
      await this.$store.dispatch('settings/set_privacyLevelList', params)
      let list = this.privacyLevelList
      console.log('保密级别=>list', list)
      const h = this.$createElement
      let attrList = []
      list.forEach((it) => {
        attrList.push(h('el-option', {
          attrs: {
            key: it.item,
            value: it.item,
            label: it.item
          }
        }))
      })
      // console.log('attrList', attrList)
      this.$msgbox({
        title: '温馨提示',
        message: h('div', null, [
          h('p', { class: 'el-message-box__message' }, '您确定要修改当前患者的保密级别 '),
          h('div', { class: 'el-message-box__input', id: 'newMessage' }, [
            h('el-select', {
              ref: 'plevelFlag',
              id: 'myInitSelectPL',
              size: 'mini',
              data: list,
              attrs: {
                value: value,
                placeholder: '请选择保密级别'
              },
              on: {
                change: (event) => {
                  this.$nextTick(() => {
                    try {
                      console.log('change=>event', event)
                      this.$refs['plevelFlag'].value = event
                    } catch (e) {
                      document.querySelector('.el-message-box .el-input input').value = event
                    }
                  }, 200)
                }
              }
            }, attrList)
          ])
        ]),
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = '保存中...'
            let value = ''
            try {
              value = this.$refs['plevelFlag'].value
            } catch (e) {
              value = document.querySelector('.el-message-box .el-input input').value
            }
            // let intValue = this.renderEmergencyInt(value)
            let intValue = list.filter(item => item.item === value) && list.filter(item => item.item === value)[0].itemValue ? list.filter(item => item.item === value)[0].itemValue : null
            console.log('beforeClose=>intValue==', intValue)
            let row = this.rowCurr
            row.privacyLevel = value
            this.$store.dispatch('patient/setRowCurr', row)
            this.$emit('refreshValue', {
              field: 'patPrivacyLevel',
              value: value
            })
            // 更新this.mix_tableData列表中的保密等级字段
            bus.$emit('changeListData', {
              row: row,
              type: 'patPrivacyLevel',
              value: value
            })
            bus.$emit('checkPostMsg', {
              type: 'patPrivacyLevel',
              data: { privacyLevel: intValue }
            })
            done()
            instance.confirmButtonLoading = false
          } else {
            done()
          }
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    },
    // 根据值来查找中文名
    renderEmergencyLabel(emerVal) {
      const emergency = this.emergencyTypes.filter(et => parseInt(et.value) == emerVal)
      if (emergency) {
        return emergency[0].label
      }
      return ''
    },
    renderEmergencyName(emerVal) {
      // console.error('emerVal', emerVal, this.emergencyTypes.filter(et => parseInt(et.value) == emerVal))
      const emergency = this.emergencyTypes.filter(et => parseInt(et.value) == emerVal)
      if (emergency) {
        return emergency[0].name
      }
      return ''
    },
    // 根据中文名来查找值
    renderEmergencyInt(emerVal) {
      console.log('-=-----进入到这里---=-=-=-=-=')
      console.log('renderEmergencyInt=>emerVal', emerVal)
      console.log('=====this.emergencyTypes======', this.emergencyTypes)
      const emergency = this.emergencyTypes.find(et => (et.label || et.name) === emerVal)
      console.log('renderEmergencyInt=>emergency', emergency)
      if (emergency) {
        return emergency.value
      } else {
        return ''
      }
    },
    // 修改检查备注
    async editRemarkInfo(text) {
      console.log('editRemarkInfo=>text', text)
      if (!this.rowCurr.patientId) {
        this.$message({
          type: 'info',
          message: '请先选择一个患者信息'
        })
        return false
      }
      console.log('this.rowCurr.remarkInfo', this.rowCurr.remarkInfo)
      this.remarkInfo = this.rowCurr.remarkInfo
      console.error('this.$createElement', this.$createElement)
      const h = this.$createElement
      this.$msgbox({
        title: '温馨提示',
        inputValue: text,
        message: h('div', null, [
          h('p', { class: 'el-message-box__message' }, '您确定要修改当前患者的检查备注 '),
          h('div', { class: 'el-message-box__input' }, [
            h('div', { class: 'el-textarea' }, [
              h('textarea', {
                attrs: {
                  placeholder: '请输入当前患者的检查备注',
                  class: 'el-textarea__inner',
                  autocomplete: 'off',
                  rows: 2,
                  id: 'commentContent'
                },
                value: this.remarkInfo,
                ref: 'myTextArea',
                on: {
                  input: (event) => {
                    this.$nextTick(() => {
                      document.getElementById('commentContent').value = event.target.value
                    })
                  }
                }
              })
            ])
          ])
        ]),
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            instance.confirmButtonLoading = true
            instance.confirmButtonText = '保存中...'
            let value = document.getElementById('commentContent').value
            let row = this.rowCurr
            row.remarkInfo = value
            this.$store.dispatch('patient/setRowCurr', row)
            // this.$emit('checkPostMsg', {
            //   type: 'patUpdateRemarkInfo',
            //   data: { grade: value }
            // })
            this.$emit('refreshValue', {
              type: 'patUpdateRemarkInfo',
              data: { newRemarkInfo: value }
            })
            bus.$emit('changeListData',{
              row: this.rowCurr,
              type: 'patUpdateRemarkInfo',
              value: value
            })
            bus.$emit('checkPostMsg', {
              type: 'patUpdateRemarkInfo',
              data: { newRemarkInfo: value, examNo: row.applyCode }
            })
            done()
            instance.confirmButtonLoading = false
          } else {
            done()
          }
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
      // document.getElementById('commentContent').value = this.remarkInfo
    },
    // 遮罩层点击
    ddtCloseBefore() {
      this.$emit('close')
    },
    getSource(row, column, val) {
      // 1 门诊 2 住院 3 体检 4 绿检 5急诊 6外院、0未知 默认0
      const ptObj = Options.patientTypeItemOptions.find(pt => pt.value === val)
      if (ptObj) {
        return ptObj.label
      }
      return ''
    }
  }
}
